package com.mask.sca.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mask.sca.system.common.Result;
import com.mask.sca.system.dto.MenuQuery;
import com.mask.sca.system.entity.Menu;
import com.mask.sca.system.service.MenuService;
import com.mask.sca.system.vo.MenuTreeVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Tag(name = "菜单管理")
@RestController
@RequestMapping("/system/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    @Operation(summary = "菜单分页查询")
    @PostMapping("/page")
    public Result<Page<Menu>> page(@RequestBody MenuQuery query) {
        return Result.success(menuService.pageMenus(query));
    }

    @Operation(summary = "菜单列表")
    @GetMapping("/list")
    public Result<List<Menu>> list() {
        return Result.success(menuService.list());
    }

    @Operation(summary = "菜单详情")
    @GetMapping("/{id}")
    public Result<Menu> get(@PathVariable Long id) {
        return Result.success(menuService.getById(id));
    }

    @Operation(summary = "新增菜单")
    @PostMapping("/add")
    public Result<Boolean> add(@RequestBody Menu menu) {
        return Result.success(menuService.save(menu));
    }

    @Operation(summary = "更新菜单")
    @PutMapping("/update")
    public Result<Boolean> update(@RequestBody Menu menu) {
        return Result.success(menuService.updateById(menu));
    }

    @Operation(summary = "删除菜单")
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.success(menuService.removeById(id));
    }

    @Operation(summary = "批量删除菜单")
    @PostMapping("/batchDelete")
    public Result<Boolean> batchDelete(@RequestBody List<Long> ids) {
        return Result.success(menuService.removeBatch(ids));
    }

    @Operation(summary = "菜单树结构")
    @GetMapping("/tree")
    public Result<List<MenuTreeVO>> tree() {
        return Result.success(menuService.tree());
    }
} 